Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

318
Vistas
Match "[abc]", "[[abc]", "[abc]]", but not "[[abc]]",

I'm trying to match [abc] unless it's "escaped" by [] from both sides (so [[abc]] is considered as escaped, but not [[abc] or [abc]]).

Closest thing I could find is (?<!\[)\[abc\](?!\]) from Match "ABC" from *ABC*, but not from **ABC**, but it ignores match if it's escaped from only one side.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The lookahead could be either at the left, or at the right to allow a single backet on the left or right, but not a double square bracket on the other side.

(?<!\[)\[abc]|\[abc](?!])

Regex demo

over 4 years ago · Santiago Trujillo Denunciar

0

@Thefourthbird's answer works, but would require that the main pattern abc be repeated, which goes against the DRY principle that most are encouraged to follow.

In the interest of maximizing code reuse, one approach would be to use a capture group to capture [abc] and then use it in a negative lookbehind pattern to ensure that it is not both preceded by a [ and followed by a ]:

(\[abc])(?<!\[\1(?=]))

Demo

Note that this works for C# because .NET happens to support variable-length lookbehind patterns, which aren't supported by many other regex engines.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda